package com.glodon.paas.databag.resource;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.glodon.paas.databag.service.DatabagService;
import com.glodon.paas.exception.PaasServerExceptionFactory;

@Component
@Path("/rvt")
public class RevitResource {
    @Autowired
    private DatabagService databagService;

    @GET
    @Path("/{databagId}/{constructionId}")
    public Response getConstrunction(@PathParam("databagId") String databagId,
            @PathParam("constructionId") String constructionId) {
        String construction = databagService.getRevitConstruction(databagId, constructionId);
        if (construction == null) {
            throw PaasServerExceptionFactory.notFoundException("not found construction " + constructionId
                    + " in databag " + databagId, null);
        }
        ResponseBuilder builder = Response.ok(construction, MediaType.APPLICATION_JSON_TYPE);
        builder.header("Cache-Control", "max-age=315360000000");
        return builder.build();
    }
}
